package controllers.managers
{
	/**
	 * 单例管理器 
	 * @author kant
	 * 
	 */	
	public class SingletonManager
	{
		private static var _instance : SingletonManager;
		private var _instanceMap : Object = {};
		
		public function SingletonManager()
		{
			if ( _instance )
			{
				throw new Error("不能直接实例化.");
			}
		}
		
		private static function getInst() : SingletonManager
		{
			if ( _instance == null )
			{
				_instance = new SingletonManager();
			}
			return _instance;
		} 
		
		/**
		 * 注册单例管理类 		
		 */		
		public static function init():void
		{
			getInst().register( LocationQueryManager.NAME, new LocationQueryManager());
			getInst().register( DataStoreManager.NAME, new DataStoreManager());
			getInst().register( SoundPlayerService.NAME, new SoundPlayerService());
			getInst().register( SoundPlayerService.NAME, new SoundPlayerService());
		}
		
		public function register( name:String, value:Object ):void
		{
			if ( _instanceMap[ name ] == null )
        	{
	        	_instanceMap[ name ] = value;         	
        	}
		}
		
		public function getServiceInstance( name:String ) : Object
		{
			return   _instanceMap[ name ] ;	 
		}
		
		public static function getServ( name:String ) : Object
		{
			return getInst().getServiceInstance( name );
		}
	}
}